﻿/*
*
*
*   My MSDN Verify Script
*
*
*/


function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

function switchText($label) {
    var alt = $label.attr("alttext");
    $label.attr("alttext", $label.html());
    $label.html(alt);
}

function beginCheck() {
    switchText($("#tips"));
    $("#result").hide();
}

function endCheck(callbackData) {
    switchText($("#tips"));

    var $pane = $("#result");
    var target = (Math.random() > 0.5 ? "partial-verify-success.html" : "partial-verify-fail.html");

    $.ajax({
        type: "GET",
        cache: false,
        url: target,
        beforeSend: function () {
            $pane.html('<div class="loading"></div>').show();
        },
        success: function (result) {
            $pane.fadeOut(function () {
                $(this).html(result).fadeToggle();
            });
        },
        error: function (xhr, msg, e) {
            alert(msg);
        }
    });

}

$(function () {

});